//
//  TiantiGroupCell.m
//  糗事百科
//
//  Created by 奚超明 on 16/5/31.
//  Copyright © 2016年 奚超明. All rights reserved.
//

#import "TiantiGroupCell.h"
#import "GroupModel.h"

@interface TiantiGroupCell ()
@property (weak, nonatomic) IBOutlet UIButton *rankBtn;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UIButton *levelBtn;
@property (weak, nonatomic) IBOutlet UILabel *fansLabel;
@property (weak, nonatomic) IBOutlet UILabel *activityLabel;
@property (weak, nonatomic) IBOutlet UILabel *locationLabel;

@end

@implementation TiantiGroupCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    // 圆角
    self.iconImageView.layer.cornerRadius = self.iconImageView.xcm_width * 0.5;
    self.iconImageView.layer.masksToBounds = YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setModel:(GroupModel *)model
{
    _model = model;
    
    NSString *rank = [model.rank stringValue];
    if ([rank isEqualToString:@"1"]) {
        [self.rankBtn setBackgroundImage:[UIImage imageNamed:@"guanjun"] forState:UIControlStateNormal];
    } else if ([rank isEqualToString:@"2"]) {
        [self.rankBtn setBackgroundImage:[UIImage imageNamed:@"yajun"] forState:UIControlStateNormal];
    } else if ([rank isEqualToString:@"3"]) {
        [self.rankBtn setBackgroundImage:[UIImage imageNamed:@"jijun"] forState:UIControlStateNormal];
    } else {
        [self.rankBtn setBackgroundImage:nil forState:UIControlStateNormal];
        [self.rankBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    }
    [self.rankBtn setTitle:rank forState:UIControlStateNormal];
    
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.icon]];
    self.nameLabel.text = model.name;
    [self.levelBtn setTitle:[model.level stringValue] forState:UIControlStateNormal];
    self.fansLabel.text = [NSString stringWithFormat:@"%@人", [model.member_num stringValue]];
    self.activityLabel.text = [NSString stringWithFormat:@"活跃度:%@", [model.active stringValue]];
    self.locationLabel.text = model.location;
}

@end
